<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/murmur/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/murmur/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/murmur/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/murmur/images/logo.svg" color="#222">

<link rel="stylesheet" href="/murmur/css/main.css">



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.1/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.css">
  <script src="//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.js"></script>

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"gitee.com","root":"/murmur/","scheme":"Gemini","version":"8.0.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":true,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"disqus","storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}};
  </script>

  <meta name="description" content="Java传统IO的认识">
<meta property="og:type" content="article">
<meta property="og:title" content="计应本的自考笔记(7)-Java IO">
<meta property="og:url" content="https://gitee.com/lianghuilin/murmur.git/university_notes/Java(7)-%E8%BE%93%E5%85%A5%E4%B8%8E%E8%BE%93%E5%87%BA/index.html">
<meta property="og:site_name" content="汇话板">
<meta property="og:description" content="Java传统IO的认识">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/lianghuilin/blog-image-warehouse/raw/master/20220423213323.png">
<meta property="article:published_time" content="2022-04-23T14:50:12.000Z">
<meta property="article:modified_time" content="2022-05-15T06:05:51.500Z">
<meta property="article:author" content="William Leung">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/lianghuilin/blog-image-warehouse/raw/master/20220423213323.png">


<link rel="canonical" href="https://gitee.com/lianghuilin/murmur.git/university_notes/Java(7)-%E8%BE%93%E5%85%A5%E4%B8%8E%E8%BE%93%E5%87%BA/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>计应本的自考笔记(7)-Java IO | 汇话板</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?a49081c570a782a242cdf6e19e1a584d";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/murmur/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">汇话板</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">设定目标，放慢步调，用温和的力量自我改革</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/murmur/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/murmur/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <section class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E6%B5%81%E7%9A%84%E6%A6%82%E5%BF%B5"><span class="nav-number">1.</span> <span class="nav-text">数据流的概念</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%BE%93%E5%85%A5%E6%B5%81"><span class="nav-number">1.1.</span> <span class="nav-text">输入流</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%BE%93%E5%87%BA%E6%B5%81"><span class="nav-number">1.2.</span> <span class="nav-text">输出流</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AD%97%E8%8A%82%E6%B5%81"><span class="nav-number">2.</span> <span class="nav-text">字节流</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%96%87%E4%BB%B6%E6%B5%81"><span class="nav-number">2.1.</span> <span class="nav-text">文件流</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%BF%87%E6%BB%A4%E5%99%A8%E6%B5%81"><span class="nav-number">2.2.</span> <span class="nav-text">过滤器流</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%BC%93%E5%86%B2%E5%8C%BA"><span class="nav-number">2.2.1.</span> <span class="nav-text">缓冲区</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%9F%BA%E4%BA%8E%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E7%9A%84%E6%95%B0%E6%8D%AE%E6%B5%81"><span class="nav-number">2.2.2.</span> <span class="nav-text">基于数据类型的数据流</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%AF%B9%E8%B1%A1%E6%B5%81"><span class="nav-number">2.3.</span> <span class="nav-text">对象流</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%BA%8F%E5%88%97%E5%8C%96"><span class="nav-number">2.4.</span> <span class="nav-text">序列化</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AD%97%E7%AC%A6%E6%B5%81"><span class="nav-number">3.</span> <span class="nav-text">字符流</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Reader%E5%92%8CWriter"><span class="nav-number">3.1.</span> <span class="nav-text">Reader和Writer</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#BufferReader%E5%92%8CBufferWriter"><span class="nav-number">3.2.</span> <span class="nav-text">BufferReader和BufferWriter</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%96%87%E4%BB%B6%E5%A4%84%E7%90%86"><span class="nav-number">4.</span> <span class="nav-text">文件处理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#File"><span class="nav-number">4.1.</span> <span class="nav-text">File</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%9A%8F%E6%9C%BA%E8%AE%BF%E9%97%AE%E6%96%87%E4%BB%B6"><span class="nav-number">4.2.</span> <span class="nav-text">随机访问文件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%96%91%E6%83%91"><span class="nav-number">5.</span> <span class="nav-text">疑惑</span></a></li></ol></div>
        </section>
        <!--/noindex-->

        <section class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">William Leung</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/murmur/archives">
          <span class="site-state-item-count">43</span>
          <span class="site-state-item-name">文章</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/murmur/categories/">
          
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/murmur/tags/">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </section>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">
      

      

  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/lianghuilin/murmur.git/university_notes/Java(7)-%E8%BE%93%E5%85%A5%E4%B8%8E%E8%BE%93%E5%87%BA/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/murmur/images/avatar.gif">
      <meta itemprop="name" content="William Leung">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="汇话板">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          计应本的自考笔记(7)-Java IO
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-04-23 22:50:12" itemprop="dateCreated datePublished" datetime="2022-04-23T22:50:12+08:00">2022-04-23</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-05-15 14:05:51" itemprop="dateModified" datetime="2022-05-15T14:05:51+08:00">2022-05-15</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/murmur/categories/%E8%AE%A1%E5%BA%94%E6%9C%AC%E7%9A%84%E8%87%AA%E8%80%83%E7%AC%94%E8%AE%B0/" itemprop="url" rel="index"><span itemprop="name">计应本的自考笔记</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>2.4k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>2 分钟</span>
    </span>
</div>

            <div class="post-description">Java传统IO的认识</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="数据流的概念"><a href="#数据流的概念" class="headerlink" title="数据流的概念"></a>数据流的概念</h2><p>程序离不开信息的输入输出，Java把不同类型的输入、输出源抽象为流(Stream)，把输入/输出的数据成为数据流(Data Stream)。</p>
<p><img src="https://gitee.com/lianghuilin/blog-image-warehouse/raw/master/20220423213323.png"></p>
<p>数据流是一组有顺序的，有起点和终点的字节集合。又分为输入数据流和输出数据流，输入数据流只能读不能写，输出数据流只能写不能读。从数据流中读取数据时，必须有一个数据源与之相连。</p>
<p>java.io包提供了4个基本抽象类，InputStream、OutputStream、Reader、Writer。</p>
<h3 id="输入流"><a href="#输入流" class="headerlink" title="输入流"></a>输入流</h3><p>输入流是只能读不能写的数据流，基于InputStream抽象类提供了一些列方法。从数据留读取数据，需要一个数据源与之连接。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 访问输入流中数据的方法：当输入流读取结束后，会得到-1，标识数据流结束。</span></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">read</span><span class="params">()</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">read</span><span class="params">(<span class="keyword">byte</span>[] b)</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">read</span><span class="params">(<span class="keyword">byte</span>[] b, <span class="keyword">int</span> off, <span class="keyword">int</span> len)</span></span>;</span><br></pre></td></tr></table></figure>

<p>实际应用中，为提高效率，读取数据时，常以系统允许的最大数据块长度作为单位读取，也就是BufferInputeStream。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 关闭数据流</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">close</span><span class="params">()</span></span>;</span><br><span class="line"><span class="comment">// 返回可从数据流中读取的字节数</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">available</span><span class="params">()</span></span>;</span><br><span class="line"><span class="comment">// 跳过数据流中指定数量的字节不读取</span></span><br><span class="line"><span class="function"><span class="keyword">long</span> <span class="title">skip</span><span class="params">()</span></span>;</span><br></pre></td></tr></table></figure>

<p>由于数据流的读取是从头到尾顺序进行的，如果需要反向读取，则需要使用回推(Push Back)操作。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 是否支持回推操作</span></span><br><span class="line"><span class="function"><span class="keyword">boolean</span> <span class="title">markSupported</span><span class="params">()</span></span>;</span><br><span class="line"><span class="comment">// 标记数据量当前位置</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">mark</span><span class="params">()</span></span>;</span><br><span class="line"><span class="comment">// 重置</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">reset</span><span class="params">()</span></span>;</span><br></pre></td></tr></table></figure>

<h3 id="输出流"><a href="#输出流" class="headerlink" title="输出流"></a>输出流</h3><p>输出数据流是从Java程序输出到计算机的数据，只能写不能读。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 写入数据流：和输入流一样，通常以系统允许的最大数据块长度作为单位读取</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">write</span><span class="params">()</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">write</span><span class="params">(<span class="keyword">byte</span> b[])</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">write</span><span class="params">(<span class="keyword">byte</span> b[], <span class="keyword">int</span> off, <span class="keyword">int</span> len)</span></span>;</span><br><span class="line"><span class="comment">// 关闭输出流</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">close</span><span class="params">()</span></span>;</span><br><span class="line"><span class="comment">// 刷新输出流，并强制写出所有缓冲的字节数据</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">flush</span><span class="params">()</span></span>;</span><br></pre></td></tr></table></figure>

<h2 id="字节流"><a href="#字节流" class="headerlink" title="字节流"></a>字节流</h2><h3 id="文件流"><a href="#文件流" class="headerlink" title="文件流"></a>文件流</h3><p>文件数据流主要通过FileInputStream和FileOutputStream两个类来处理，其数据源和数据终点都应该是文件。</p>
<p>值得注意的是，FileInputStream类的实例对象，如果所指定的文件不存在会产生FileNotFoundException异常，读写文件或生成新文件时发生错误会产生IOException，都需要加以捕获或声明。FileOutputStream类的实例，如果指定的文件不存在，则会创建新文件。如果存在，会覆盖文件原有的数据。</p>
<h3 id="过滤器流"><a href="#过滤器流" class="headerlink" title="过滤器流"></a>过滤器流</h3><p>过滤器数据流在创建时，就与一个已存在的数据流相连，用于对该数据流进行特定处理</p>
<h4 id="缓冲区"><a href="#缓冲区" class="headerlink" title="缓冲区"></a>缓冲区</h4><p>缓冲区数据流有BufferInputStream和BufferOutputStream，它们的作用是在原有数据流的基础上增加一个缓冲区。当读写数据时，数据以块为单位先进入缓冲区，后续读写数据都作用于缓冲区。从而降低不同硬件设备之间的速度差异，提高I/O效率。</p>
<h4 id="基于数据类型的数据流"><a href="#基于数据类型的数据流" class="headerlink" title="基于数据类型的数据流"></a>基于数据类型的数据流</h4><p>DataInputStream和DataOutputStream允许通过数据流来读写Java基础数据类型，包括boolean、float等。</p>
<p>但由于字符编码的原因，应该避免使用这些方法。比如对字符进行操作的时候，应该使用Reader和Writer类的方法进行操作。</p>
<h3 id="对象流"><a href="#对象流" class="headerlink" title="对象流"></a>对象流</h3><p>Java不仅支持对基础数据类型进行读写，还支持把对象作为文件数据流进行读写。通过java.io的ObjectInputStream和ObjectOutputStream两个类实现。</p>
<h3 id="序列化"><a href="#序列化" class="headerlink" title="序列化"></a>序列化</h3><p>将对象的状态记录存储起来，称为对象的持久化。</p>
<p>对象通过变量的数值来描述实例的状态，记录对象就是记录这些数值。将对象转换为字节序列的过程称为序列化，把字符序列恢复为对象的过程称为反序列化。如果变量值是另一个对象的引用，那么引用对象也要进行序列化，这个过程是递归的。</p>
<p>通过java.io.Serializable接口支持将Java对象进行序列化。序列化对象，必须与ObjectInputStream/ObjectOutputStream联系起来。前者使用readObject方法从输入流读取对象，后者用writeObject方法将对象保存到输出流。</p>
<p>虽然序列号只能保存对象的非静态成员变量的值，但有些对象涉及需要保密的数据，不希望存到永久介质当中的，可在变量前加transient关键字，表明该成员不适合进行序列化。</p>
<h2 id="字符流"><a href="#字符流" class="headerlink" title="字符流"></a>字符流</h2><h3 id="Reader和Writer"><a href="#Reader和Writer" class="headerlink" title="Reader和Writer"></a>Reader和Writer</h3><p>Java Reader和Writer也是抽象类，通过它们实现对不同平台之间的字符处理。使用的是Unicode字符集来表示字符串和字符。</p>
<p>Reader和Writer底下有InputStreamReader和OutputStreamWriter类</p>
<h3 id="BufferReader和BufferWriter"><a href="#BufferReader和BufferWriter" class="headerlink" title="BufferReader和BufferWriter"></a>BufferReader和BufferWriter</h3><p>字符流同样拥有缓冲区用以提升IO效率，分别是BufferReader和BufferWriter</p>
<h2 id="文件处理"><a href="#文件处理" class="headerlink" title="文件处理"></a>文件处理</h2><h3 id="File"><a href="#File" class="headerlink" title="File"></a>File</h3><p>java.io.File提供对文件信息获取和操作文件的方法</p>
<ul>
<li>创建File对象</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 创建文件方法1</span></span><br><span class="line">File myFile;</span><br><span class="line">myFile = <span class="keyword">new</span> File(<span class="string">&quot;myfile&quot;</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 创建文件方法2</span></span><br><span class="line">myFile = <span class="keyword">new</span> File(<span class="string">&quot;/&quot;</span>, <span class="string">&quot;myfile&quot;</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 创建文件方法3</span></span><br><span class="line">File myDir = <span class="keyword">new</span> File(<span class="string">&quot;/&quot;</span>);</span><br><span class="line">myFile = <span class="keyword">new</span> File(myDir, <span class="string">&quot;myfile&quot;</span>);</span><br></pre></td></tr></table></figure>

<h3 id="随机访问文件"><a href="#随机访问文件" class="headerlink" title="随机访问文件"></a>随机访问文件</h3><p>Java提供了RandonAccessFile随机访问文件</p>
<h2 id="疑惑"><a href="#疑惑" class="headerlink" title="疑惑"></a>疑惑</h2><ul>
<li>不实现Serializable接口，与@transient注解的区别</li>
</ul>

    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>William Leung
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://gitee.com/lianghuilin/murmur.git/university_notes/Java(7)-%E8%BE%93%E5%85%A5%E4%B8%8E%E8%BE%93%E5%87%BA/" title="计应本的自考笔记(7)-Java IO">https://gitee.com/lianghuilin/murmur.git/university_notes/Java(7)-输入与输出/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/murmur/crush_notes/Vue%20template+script+scss%E4%B8%AD%E4%BD%BF%E7%94%A8asserts%E8%B7%AF%E5%BE%84%E5%88%AB%E5%90%8D/" rel="prev" title="别再../../引assets了，使用路径别名吧">
                  <i class="fa fa-chevron-left"></i> 别再../../引assets了，使用路径别名吧
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/murmur/crush_notes/vue-echarts%E9%85%8D%E7%BD%AEmarkLine%E7%9A%84%E4%B8%80%E4%BA%9B%E7%8A%B6%E5%86%B5/" rel="next" title="vue-echarts配置markLine的一些状况">
                  vue-echarts配置markLine的一些状况 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






      

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

    </div>
  </main>

  <footer class="footer">
    <div class="footer-inner">
      

      

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">William Leung</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">142k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">2:09</span>
  </span>
</div>
<div class="busuanzi-count">
    <span id="busuanzi_container_site_uv">
      本站访客数<span id="busuanzi_value_site_uv"></span>人次
    </span>
    <span id="busuanzi_container_site_pv">
        本站总访问量<span id="busuanzi_value_site_pv"></span>次
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="//cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/murmur/js/utils.js"></script><script src="/murmur/js/motion.js"></script><script src="/murmur/js/next-boot.js"></script>

  
















  <script>
    NProgress.configure({
      showSpinner: true
    });
    NProgress.start();
    document.addEventListener('readystatechange', () => {
      if (document.readyState === 'interactive') {
        NProgress.inc(0.8);
      }
      if (document.readyState === 'complete') {
        NProgress.done();
      }
    });
    document.addEventListener('pjax:send', () => {
      NProgress.start();
    });
    document.addEventListener('pjax:success', () => {
      NProgress.done();
    });
  </script>


  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>








  

  

</body>
</html>
